<div class="panel-body">
	<div class="table-responsive">
		<div class="dataTables_wrapper form-inline" id="dataTables-example_wrapper" role="grid">
			<div class="row" style="padding-bottom: 15px">
				<div class="col-sm-9">

				</div>
				<div class="col-sm-3">

				</div>
			</div>
			<form id="EditShop" method="post" action="" novalidate="novalidate" class="form-inline">
				<div class="row">
					<div class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>地市:</label>
							<input class="form-control" id="cityName" type="text" name="cityName" /></div>
					</div>
					<div class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>区/县:</label>
							<select class="form-control" id="areaname" name="countryName" onchange="changearea()" style="width: 160px;">
								<option value="">区/县</option>
							</select>
						</div>
					</div>
					<div class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>分局:</label>
							<select class="form-control" id="branchOfficeId" name="branchOffice" onchange="changeTwon()" style="width: 160px;">
								<option value="">分局</option>
							</select>
						</div>
					</div>
					<div class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>网格:</label>
							<select class="form-control" id="gridId" name="gridName" style="width: 160px;">
								<option value="">网格</option>
							</select>
						</div>
					</div>
					<div class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>店铺名称:</label>
							<input class="form-control" id="name" type="text" name="name" /></div>
					</div>
					<!--<div class="col-lg-6 col-md-6">
			<div class="form-group">
				<label>商铺类型:</label>
				<select class="form-control" id="type" name="type" style="width: 160px;">
					<option value="">商铺类型</option>
					<option value="餐饮娱乐">餐饮娱乐</option>
					<option value="批发零售">批发零售</option>
					<option value="快递物流">快递物流</option>
					<option value="药品药业">药品药业</option>
					<option value="宾馆酒店">宾馆酒店</option>
					<option value="楼宇市场">楼宇市场</option>
					<option value="园区市场">园区市场</option>
					<option value="聚类市场">聚类市场</option>
				</select>
			</div>
		</div>-->
					<div class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>乡/镇/街道办:</label>
							<input class="form-control" id="town" type="text" name="town" /></div>
					</div>
					<div class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>街/村/小区:</label>
							<input class="form-control" id="village" type="text" name="village" />
						</div>
					</div>

					<div class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>街道门牌号:</label>
							<input class="form-control" id="villageNo" type="text" name="villageNo" />
						</div>
					</div>
					<div class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>栋/单元/组:</label>
							<input class="form-control" id="cell" type="text" name="cell" /></div>
					</div>
					<div class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>经度:</label>
							<input class="form-control" id="longitude" type="text" name="longitude" /></div>
					</div>
					<div class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>纬度:</label>
							<input class="form-control" id="latitude" type="text" name="latitude" /></div>
					</div>
					<div class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>营销状态:</label>
							<select class="form-control" onchange="StatusChange()" id="marketingStatus" name="marketingStatus" style="width: 160px;">
								<option value="">营销状态</option>
								<option value="未拜访">未拜访</option>
								<option value="已拜访">已拜访</option>
								<option value="已签约">已签约</option>
							</select>
						</div>
					</div>
					<div id="reMarkShow" class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>备注:</label>
							<input class="form-control" id="reMark" type="text" name="reMark" /></div>
					</div>
					<div id="packageFeeShow" class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>资费套餐:</label>
							<select class="form-control" id="packageFee" name="packageFee" style="width: 160px;">
								<option value="">资费套餐</option>
								<option value="和飞速-标准版">和飞速-标准版</option>
								<option value="小微版">小微版</option>
								<option value="楼宇版">楼宇版</option>
								<option value="和商务">和商务</option>
								<option value="家庭宽带">家庭宽带</option>
								<option value="和酒店">和酒店</option>
							</select>
						</div>
					</div>
					<div id="expiryDateShow" class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>资费到期时间:</label>
							<input class="form-control" id="expiryDate" data-date-format="yyyy-mm-dd" type="text" name="expiryDate">
						</div>
					</div>
					<div class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>行业类别:</label>
							<select class="form-control" onchange="industryChange()" id="industry" name="industryCategory" style="width: 160px;">
								<option value="">行业类别</option>
								<option value="宾馆酒店">宾馆酒店</option>
								<option value="楼宇园区">楼宇园区</option>
								<option value="连锁集团">连锁集团</option>
								<option value="快递">快递</option>
								<option value="网吧">网吧</option>
							</select>
						</div>
					</div>
					<div id="hotelCategoryShow" class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>酒店类型:</label>
							<select class="form-control" id="hotelCategory" name="hotelCategory" style="width: 160px;">
								<option value="">酒店类型</option>
								<option value="星级">星级</option>
								<option value="商务">商务</option>
								<option value="农家乐">农家乐</option>
							</select>
						</div>
					</div>
					<div id="hotelRoomCountShow" class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>房间总数:</label>
							<input class="form-control" id="hotelRoomCount" type="text" name="hotelRoomCount" /></div>
					</div>

					<div id="hotelSignRoomCountShow" class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>已签约房间数:</label>
							<input class="form-control" id="hotelSignRoomCount" type="text" name="hotelSignRoomCount" /></div>
					</div>
					<div id="sceneShow" class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>楼宇场景:</label>
							<select class="form-control" id="scene" name="scene" style="width: 160px;">
								<option value="">楼宇场景</option>
								<option value="写字楼">写字楼</option>
								<option value="CBD">CBD</option>
								<option value="聚类">聚类</option>
								<option value="园区">园区</option>
							</select>
						</div>
					</div>
					<div id="buildingNameShow" class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>楼宇名称:</label>
							<input class="form-control" id="buildingName" type="text" name="buildingName" /></div>
					</div>
					<div class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>网络供应商:</label>
							<select class="form-control" id="isp" name="isp" style="width: 160px;">
								<option value="">网络供应商</option>
								<option value="移动">移动</option>
								<option value="电信">电信</option>
								<option value="联通">联通</option>
								<option value="其他">其他</option>
							</select>
						</div>
					</div>
					<div class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>月消费:</label>
							<input class="form-control" id="monthlyConsumption" type="text" name="monthlyConsumption" /></div>
					</div>
					<div class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>网络资源:</label>
							<select class="form-control" id="networkSource" name="networkSource" style="width: 160px;">
								<option value="">请选择</option>
								<option value="否">否</option>
								<option value="是">是</option>
							</select>
						</div>
					</div>
					<!--<div class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>店长名称:</label>
							<input class="form-control" id="shopKeeper" type="text" name="shopKeeper" /></div>
					</div>-->
					<div class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>店长手机号码:</label>
							<input class="form-control" id="shopKeeperPhone" type="text" name="shopKeeperPhone" /></div>
					</div>
					<div class="col-lg-6 col-md-6">
						<div class="form-group">
							<label>店员数量:</label>
							<input class="form-control" id="shopMemNum" type="text" name="shopMemNum" /></div>
					</div>
					<div class="col-lg-6 col-md-6">
						<div class="form-group" style="height: 45px;">
							<label>门头照:</label>
							<input type="file" style="display: inline-block;width:160px;" value="上传" id="picPathPost">
						</div>
					</div>
					<div class="col-lg-6 col-md-6">
						<div class="form-group" style="height: 45px;">
							<label>拜访照片:</label>
							<input type="file" style="display: inline-block;width:160px;" value="上传" id="visitPicPathPost">
						</div>
					</div>
				</div>
				<input type="hidden" id="id" name="id" />
				<input type="hidden" id="uuid" name="uuid" />
				<input type="hidden" id="mangerId" name="mangerId" />
				<input type="hidden" id="picPath" name="picPath" />
				<input type="hidden" id="visitPicPath" name="visitPicPath" />
			</form>

			<div class="row" style="margin: 100px">
				<div class="col-sm-9">

				</div>
				<div class="col-sm-3">
					<div class="dataTables_filter" id="dataTables-example_filter" style="float: left;margin-left: 20px;">
						<a class="btn btn-serch" onclick="SaveShop()">保存</a>
					</div>
					<div class="dataTables_filter" id="dataTables-example_filter" style="float: left;margin-left: 20px;">
						<a class="btn btn-serch" style="background-color:#dedddd !important ;" onclick="cancel()">取消</a>
					</div>

				</div>
			</div>
		</div>

	</div>
</div>

<script>
	$(function() {
		$("#mangerId").val(GLOBAL.userId);
		$("#picPathPost").change(function() {
			run(this, function(data) {
				uploadImage(data, "#picPathPost", "#picPath");
			});
		});
		$("#visitPicPathPost").change(function() {
			run(this, function(data) {
				uploadImage(data, "#picPathPost", "#picPath");
			});
		});

		$("#expiryDate").datetimepicker({
			format: 'yyyy-mm-dd',
			todayHighlight: 1,
			minView: "month", //设置只显示到月份
			autoclose: 1 //选择后自动关闭
		});
		GetCostomer();
		GetArea();
	})
	//请求商客经理
	function GetCostomer() {
		var json = {
			url: GLOBAL.URL + "/customer/list",
			type: 'post',
			data: {
				"page": 1,
				"limit": 150000000
			},
			successfn: function(data) {
				setCustomerList(data.page.list);
			},
			errorfn: function() {
				//ajaxUpdataTable();
				//$.ligerDialog.warn("系统繁忙，请稍候再试");
			}
		};
		ajaxdata(json);
	}
	//加载商客经理列表数据
	function setCustomerList(data) {
		var str = "<option value=''>商客经理</option>";
		if(data != null) {
			for(var i = 0; i < data.length; i++) {
				str += "<option value='" + data[i].userId + "'>" + data[i].realName + "</option>";
			}
		}
		$("#mangerId").html(str);
	}
	//获取区县
	function GetArea() {
		var json = {
			url: GLOBAL.URL + "/guidinfo/getAllAreaList",
			type: 'post',
			data: {
				"queryType": 0
			},
			successfn: function(data) {
				SetArea(data);
			},
			errorfn: function() {
				//ajaxUpdataTable();
				//$.ligerDialog.warn("系统繁忙，请稍候再试");
			}
		};
		ajaxdata(json);
	}

	function SetArea(data) {
		var str = '<option value="">区/县</option>';
		for(var i = 0; i < data.data.length; i++) {
			str += '<option value="' + data.data[i].area + '">' + data.data[i].area + '</option>';
		}
		$("#areaname").html(str);
	}
	//区县点击
	function changearea() {
		if($("#areaname").val() == "") {
			$("#branchOfficeId").html('<option value="">分局</option>');
			$("#gridId").html('<option value="">网格</option>');
		} else {
			GetWork($("#areaname").val());
		}
	}
	//获取分局
	function GetWork(areaname) {
		var json = {
			url: GLOBAL.URL + "/guidinfo/getAllAreaList",
			type: 'post',
			data: {
				"area": areaname,
				"queryType": 1
			},
			successfn: function(data) {
				SetWork(data);
			},
			errorfn: function() {
				//ajaxUpdataTable();
				//$.ligerDialog.warn("系统繁忙，请稍候再试");
			}
		};
		ajaxdata(json);
	}

	function SetWork(data) {
		var str = '<option value="">分局</option>';
		for(var i = 0; i < data.data.length; i++) {
			str += '<option value="' + data.data[i].town + '">' + data.data[i].town + '</option>';
		}
		$("#branchOfficeId").html(str);
	}

	function changeTwon() {
		if($("#areaname").val() == "" || $("#branchOfficeId").val() == "") {
			$("#gridId").html('<option value="">网格</option>');
		} else {
			Getwangge($("#areaname").val(), $("#branchOfficeId").val());
		}
	}
	//获取网格
	function Getwangge(areaname, branchOfficeId) {
		var json = {
			url: GLOBAL.URL + "/guidinfo/getAllAreaList",
			type: 'post',
			data: {
				"area": areaname,
				"town": branchOfficeId,
				"queryType": 2
			},
			successfn: function(data) {
				SetWangge(data);
			},
			errorfn: function() {
				//ajaxUpdataTable();
				//$.ligerDialog.warn("系统繁忙，请稍候再试");
			}
		};
		ajaxdata(json);
	}

	function SetWangge(data) {
		var str = '<option value="">网格</option>';
		for(var i = 0; i < data.data.length; i++) {
			str += '<option value="' + data.data[i].branchOffice + '">' + data.data[i].branchOffice + '</option>';
		}
		$("#gridId").html(str);
	}

	//营销状态change事件
	function StatusChange() {
		var status = $("#marketingStatus").val();
		if(status == "已拜访") {
			$("#packageFeeShow").hide();
			$("#expiryDateShow").hide();
			$("#reMarkShow").show();

			$("#packageFeeShow").val("");
			$("#expiryDateShow").val("");
		} else if(status == "已签约") {
			$("#packageFeeShow").show();
			$("#expiryDateShow").show();
			$("#reMarkShow").hide();

			$("#reMarkShow").val("");
		} else {
			$("#packageFeeShow").hide();
			$("#expiryDateShow").hide();
			$("#reMarkShow").hide();

			$("#reMarkShow").val("");
			$("#packageFeeShow").val("");
			$("#expiryDateShow").val("");
		}
	}

	//行业类别
	function industryChange() {
		var industryCategory = $("#industry").val();
		if(industryCategory == "宾馆酒店") {
			$("#hotelCategoryShow").show();
			$("#hotelRoomCountShow").show();
			$("#hotelSignRoomCountShow").show();
			$("#sceneShow").hide();
			$("#buildingNameShow").hide();

			$("#sceneShow").val("");
			$("#buildingNameShow").val("");

		} else if(industryCategory == "楼宇园区") {
			$("#hotelCategoryShow").hide();
			$("#hotelRoomCountShow").hide();
			$("#hotelSignRoomCountShow").hide();
			$("#sceneShow").show();
			$("#buildingNameShow").show();

			$("#hotelCategoryShow").val("");
			$("#hotelRoomCountShow").val("");
			$("#hotelSignRoomCountShow").val("");
		} else {
			$("#hotelCategoryShow").hide();
			$("#hotelRoomCountShow").hide();
			$("#hotelSignRoomCountShow").hide();
			$("#sceneShow").hide();
			$("#buildingNameShow").hide();

			$("#hotelCategoryShow").val("");
			$("#hotelRoomCountShow").val("");
			$("#hotelSignRoomCountShow").val("");
			$("#sceneShow").val("");
			$("#buildingNameShow").val("");
		}
	}

	function run(input_file, get_data) {
		/*input_file：文件按钮对象*/
		/*get_data: 转换成功后执行的方法*/
		if(typeof(FileReader) === 'undefined') {
			AlertInfo("抱歉，你的浏览器不支持 FileReader，不能将图片转换为Base64，请使用现代浏览器操作！");
		} else {
			try {
				/*图片转Base64 核心代码*/
				var file = input_file.files[0];
				//这里我们判断下类型如果不是图片就返回 去掉就可以上传任意文件  
				if(!/image\/\w+/.test(file.type)) {
					AlertInfo("请确保文件为图像类型");
					return false;
				}
				var reader = new FileReader();
				reader.onload = function() {
					get_data(this.result);
				}
				reader.readAsDataURL(file);
			} catch(e) {
				AlertInfo('图片转Base64出错啦！' + e.toString())
			}
		}
	}

	function uploadImage(img, postId, fileId) {
		//判断是否有选择上传文件
		var imgPath = $(postId).val();
		if(imgPath == "") {
			AlertInfo("请选择上传图片！");
			return;
		}
		//判断上传文件的后缀名
		var strExtension = imgPath.substr(imgPath.lastIndexOf('.') + 1);
		if(strExtension != 'jpg' && strExtension != 'gif' &&
			strExtension != 'png' && strExtension != 'bmp') {
			alert("请选择图片文件");
			return;
		}
		$.ajax({
			type: "POST",
			url: GLOBAL.URL + "/uploadBase64",
			name: 'base64Data',
			data: {
				base64Data: img
			}, //视情况将base64的前面字符串data:image/png;base64,删除
			success: function(data) {
				$(fileId).val(data.filePath);
				AlertInfo("上传成功！");
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				AlertInfo("上传失败，请检查网络后重试");
			}
		});
	}

	function cancel() {
		$("#tabC").load("Page/shopmanage/shop/shop.html");
	}

	function SaveShop() {
		var num = Math.random();
		$("#EditShop").ajaxSubmit({
			url: GLOBAL.URL + "/shopinfo/update" + "?" + num,
			type: 'POST',
			dataType: "json",
			ContentType: 'application/json',
			xhrFields: {
				withCredentials: true
			},
			crossDomain: true,
			success: function(msg) {
				if(msg.code == "0") {
					AlertInfo("操作成功！");
					$("#MainContent").hide();
					$("#tabC").load("Page/shopmanage/shop/shop.html");
					//$("#EditDialog").removeClass("md-show");
					getdata(1);
				} else if(msg.code == "403") {
					AlertInfo("操作失败！" + msg.msg);
					window.location.href = "login.html";
				} else {
					AlertInfo("操作失败！" + msg.msg);
				}
			}
		});
	}
</script>